﻿using System;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using DNT.RavenQA.Web.App_Start;
using DNT.RavenQA.Web.Infrastructure.IoC;
using DNT.RavenQA.Web.ViewModels;
using log4net.Config;
using StructureMap;

namespace DNT.RavenQA.Web
{
    public class MvcApplication : HttpApplication
    {
        public MvcApplication()
        {
            EndRequest += OnEndRequest;
        }

        private static void OnEndRequest(Object sender, EventArgs eventArgs)
        {
            ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
        }

        protected void Application_Start()
        {
            XmlConfigurator.Configure();
            StructureMapBootstrapper.Initialize();
            AreaRegistration.RegisterAllAreas();
            ModelBinders.Binders.Add(typeof(LogOnViewModel), new LogOnViewModelBinder());
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}